package com.totoro.utils;

import lombok.SneakyThrows;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author TOTORO
 * @date 2021/8/1 19:23
 */
public class TimeIntervalUtil {
    public static final String DAY = "day",MINUTE = "minute";
    @SneakyThrows
    public static boolean isReach(String beforeDateStr, int time, String timeType){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long beforeDateLong = simpleDateFormat.parse(beforeDateStr).getTime();
        long nowDateLong = System.currentTimeMillis();
        long reachLong = 0;
        if(timeType.equals(DAY)) {
            reachLong = time * 86400000L;
        }
        if(timeType.equals(MINUTE)){
            reachLong = time * 60000L;
        }
        if(nowDateLong - beforeDateLong >= reachLong){
            return true;
        }
        return false;
    }
}
